package com.example.test;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class EnviarmsjActivity extends ActionBarActivity {
	
	TextView usernameEnviarTextView;
	EditText mensajeEnviar;
	Button enviarMsjBtn;
	Bundle bundle;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_enviarmsj);
		bundle = getIntent().getExtras();
		
		usernameEnviarTextView = (TextView) findViewById(R.id.usernameEnviarMensajeTextView);
		mensajeEnviar = (EditText) findViewById(R.id.mensajeEditText);
		enviarMsjBtn = (Button) findViewById(R.id.enviarmsjBtn);
		
		usernameEnviarTextView.setText(
				controller.Controlador.obtenerUsuarioPorToken(bundle.getString("tv_token")));
		
		enviarMsjBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				controller.Controlador.enviarMensaje(domain.Sesion.username,
						controller.Controlador.obtenerUsuarioPorToken(bundle.getString("tv_token")),
								mensajeEnviar.getText().toString());
				
				Toast error = Toast.makeText(
        				getApplicationContext(),
        				"Mensaje Enviado!", 
        				Toast.LENGTH_LONG);
        		error.show();
				
			}
		});
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.enviarmsj, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
